home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
2510.ZIP
/
TRSOURCE.EXE
/
_TR_CRPT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-22
|
3KB
|
65 lines
/*********
*
* _TR_CRPT.C
*
* by Leonard Zerman and Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: _tr_crypt( <*string>, <*password>, <*ret> )
*
* Return: <expC> of <string> encoded/decode according to <password>.
* Return string will be same length as <string>.
* Unchanged <string> if <password> is less than 3 characters.
*
* Note..: All parameters are <*expC>.
*
* The following encryption algorithm handles the full
* international ASCII character set. Passnum is an
* integer between 1 and 254 that receives a value
* returned from _tr_pnum based on the password.
* Passnum is a seed for the encryption-key variable
* that is modified in the for-loop by the position
* of the current character in reference to the total
* string (i - len). This produces a non-repeating
* pattern even if all the characters are the same,
* thus hiding the length of the password key.
* The password characters are always being rotated
* in a circular manner (que).
* ret[i] gets the bitwise XOR of the character with
* the XOR of passnum and the current character in the
* password que. This gives 24 bits of encryption for
* each character.
*
* This encryption/decryption program can be broken
* by any computer-literate person with access to this
* source code or a knowledge of cryptography.
*********/
#include "trlib.h"
char *_tr_crypt( instr, pwstr, ret )
char *instr, *pwstr, *ret; /* pointers to string, password, */
{ /* and return string */
int i, j, len, pwlen, passnum;
char buff[1];
len = _tr_strlen( instr ); /* length of string */
pwlen = _tr_strlen( pwstr ); /* length of password */
passnum = (int) ((((_tr_pnum(pwstr)/997) - 1) % 254 ) + 1);
/* get seed value */
for ( i = j = 0; i < len; i++ ) /* process whole string */
{
passnum = (int) (((passnum + ( i - len )) - 1 ) % 254) + 1;
buff[0] = (instr[i] ^ (passnum ^ pwstr[j]) ); /* XOR 3 var's */
ret[i] = (buff[0] ? buff[0] : instr[i]); /* if NULL return char */
j = ( j >= pwlen ? 0 : j++ ); /* password que control variable */
}
ret[i] = NULLC; /* NULL terminate string */
return( ret ); /* send back encrypted string */
}
/* eof _tr_crpt */